package top.kaoshanji.p1ch02a;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * author kaoshanji
 * ^_^
 * create time 2024/12/23 15:41
 */
public class MethodUsage {

    private static final Logger logger = LogManager.getLogger(MethodUsage.class);

    public static void main(String[] args) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException {

        MethodUsage mu = new MethodUsage();
        mu.useMethod();

    }

    public void useMethod() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        logger.info("...代码清单 p1ch02a-05：使用反射API获取和使用公开和私有方法(2.2.3节)...");

        MethodContainer mc = new MethodContainer();
        Method publicMethod = MethodContainer.class.getDeclaredMethod("publicMethod");
        publicMethod.invoke(mc);

        Method privateMethod = MethodContainer.class.getDeclaredMethod("privateMethod");
        privateMethod.setAccessible(true);
        privateMethod.invoke(mc);

    }

}
